package com.bwie.controller;

import com.alipay.api.AlipayApiException;
import com.bwie.bean.AliPayBean;
import com.bwie.config.SnowFlakeUtil;
import com.bwie.service.PayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/ali")
public class OrderController {

    /**日志对象*/
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private PayService payService;

    @RequestMapping("/pay")
    @ResponseBody
    public String alipay(String shopName,String seckillPrice) throws AlipayApiException {

//        logger.info("商户订单号为{},订单名称为{},付款金额为{},商品描述{}", outTradeNo, subject, totalAmount, body);
        System.out.println(shopName);
        System.out.println(seckillPrice);
        AliPayBean alipayBean = new AliPayBean();
        String randomStr = SnowFlakeUtil.getRandomStr();
        alipayBean.setOut_trade_no(randomStr);
        alipayBean.setSubject("荷花刘玉溪刘");
        alipayBean.setTotal_amount("12.5");
        alipayBean.setBody("荷花刘玉溪刘");
        return payService.aliPay(alipayBean);
    }



    @RequestMapping("/success")
    @ResponseBody
    public String success(){
        return "交易成功！";
    }


    @RequestMapping(value = "/index")
    public String payCoin(){
        return "index.html";
    }
}

